home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Files / MoreIsBetter / MIB-Libraries / Sources / MoreDialogs.cp < prev    next >
Encoding:
Text File  |  1998-09-25  |  2.4 KB  |  118 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MoreDialogs.cp
  3.  
  4.     Contains:    
  5.  
  6.     Written by:    Pete Gontier (PCG)
  7.  
  8.     Copyright:    Copyright (c) 1998 Apple Computer, Inc.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     7/24/98    PCG        eliminate dependency on 'qd'
  13.          <1>     6/16/98    PCG     initial checkin
  14. */
  15.  
  16. #include <Sound.h>
  17.  
  18. #include "MoreDialogs.h"
  19.  
  20. pascal void SaferShortenDITL (DialogPtr dialog, DialogItemIndex index)
  21. {
  22.     while (index--) ShortenDITL (dialog, 1);
  23. }
  24.  
  25. pascal DialogPtr MoreGetNewDialog (short dlogResID)
  26. {
  27.     return GetNewDialog (dlogResID, nil, kFirstWindowOfClass);
  28. }
  29.  
  30. pascal void SetDialogItemString (DialogPtr dialog, DialogItemIndex index, ConstStr255Param str)
  31. {
  32.     if (MoreAssert (dialog && index))
  33.     {
  34.         short iType; Rect iRect; Handle iHandle;
  35.         GetDialogItem (dialog,index,&iType,&iHandle,&iRect);
  36.         SetDialogItemText (iHandle, str ? str : "\p");
  37.     }
  38. }
  39.  
  40. pascal void GetDialogItemString (DialogPtr dialog, DialogItemIndex index, StringPtr str)
  41. {
  42.     if (MoreAssert (dialog && index && str))
  43.     {
  44.         short iType; Rect iRect; Handle iHandle;
  45.         GetDialogItem (dialog,index,&iType,&iHandle,&iRect);
  46.         GetDialogItemText (iHandle, str);
  47.     }
  48. }
  49.  
  50. pascal void SelectAllDialogItemText (DialogPtr dialog, DialogItemIndex index)
  51. {
  52.     SelectDialogItemText (dialog,index,0,32767);
  53. }
  54.  
  55. pascal void MoveableModalDialog (ModalFilterUPP mfp, short *itemHit)
  56. {
  57.     //
  58.     //    I just made this logic up.
  59.     //    In a perfect world, I would steal the implementation
  60.     //    of the real ModalDialog and tweak it a little bit.
  61.     //    Consider it a to-do item.
  62.     //
  63.  
  64.     EventRecord        event;
  65.     DialogRef        pop, dummy;
  66.     WindowRef        whichWindow;
  67.     short            partCode;
  68.     Boolean            handledIt = false;
  69.  
  70.     pop = FrontWindow( );
  71.     *itemHit = kDialogItemIndexNone;
  72.  
  73.     do
  74.     {
  75.         WaitNextEvent (everyEvent & ~highLevelEventMask, &event, GetCaretTime( ), nil);
  76.  
  77.         switch (event.what)
  78.         {
  79.             case mouseDown:
  80.  
  81.                 partCode = FindWindow (event.where, &whichWindow);
  82.  
  83.                 if (whichWindow != pop)
  84.                 {
  85.                     if (partCode == inSysWindow)
  86.                         SystemClick (&event,whichWindow);
  87.                     else
  88.                         SysBeep(10);
  89.                     break;
  90.                 }
  91.  
  92.                 if (inDrag == partCode)
  93.                 {
  94.                     Rect dragBounds;
  95.  
  96.  
  97.                     dragBounds = (**GetMainDevice ( )).gdRect;
  98.                     InsetRect (&dragBounds, 4, 4);
  99.                     DragWindow (pop, event.where, &dragBounds);
  100.                     break;
  101.                 }
  102.  
  103.                 // fall thru
  104.  
  105.             default:
  106.  
  107.                 if (mfp)
  108.                     handledIt = CallModalFilterProc (mfp,pop,&event,itemHit);
  109.  
  110.                 if (!handledIt && IsDialogEvent(&event))
  111.                     DialogSelect(&event,&dummy,itemHit);
  112.  
  113.                 break;
  114.         }
  115.     }
  116.     while (*itemHit == kDialogItemIndexNone);
  117. }
  118.